package org.ecpkn.PAGridSim.core.offlineOptimization;

import java.util.ArrayList;

import org.ecpkn.PAGridSim.core.PAEntityFactory;
import org.ecpkn.PAGridSim.core.configuration.Configuration;
import org.ecpkn.PAGridSim.core.configuration.Configuration.Const;
import org.ecpkn.PAGridSim.core.gridsimEntity.paMachine.PAMachine;

public class OptimizedResultEntry {
	// TODO:utiliation can be used for loadbalance
	private double timePoint;
	private Double optimizedUtilization_;

	private double optimizedFrequency_;
	private int optimizedNodesNumber_;
	private ArrayList<PAMachine> modelMachineList;

	public ArrayList<PAMachine> getModelMachineList() {
		return modelMachineList;
	}

	public void setModelMachineList(ArrayList<PAMachine> modelMachineList) {
		this.modelMachineList = modelMachineList;
	}
	
	public void setOptimizedUtilization_(double optimizedUtilization_) {
		this.optimizedUtilization_ = optimizedUtilization_;
	}

	public OptimizedResultEntry(Double optimizedUtilization_,
			double optimizedFrequency_, int optimizedNodesNumber_) {
		this.optimizedUtilization_ = optimizedUtilization_;
		this.optimizedFrequency_ = optimizedFrequency_;
		this.optimizedNodesNumber_ = optimizedNodesNumber_;
	}

	public Double getOptimizedUtilization_() {
		return optimizedUtilization_;
	}

	public double getOptimizedFrequency_() {
		return optimizedFrequency_;
	}

	public int getOptimizedNodesNumber_() {
		return optimizedNodesNumber_;
	}

	public double getOptimizedPower_() {
		double power=0;		
		if(modelMachineList==null){
			return 0;
		}
		if(modelMachineList.size()==0){
			return 0;
		}
		for(PAMachine m:modelMachineList){
			power=power+m.getPower();
		}
		return power;
	}
	
	public double getTheoreticalOptimizedPower_() throws Exception {	
		PAMachine m=PAEntityFactory.createCustomizedMachine(
				Configuration.getInstance().getParameterString(
						Const.SIMULATION_MACHINE), 999999, 1, (int) this.optimizedFrequency_);
		//TODO:utilization?
		return m.getPower()*this.optimizedNodesNumber_;
	}

	public double getTimePoint() {
		return timePoint;
	}

	public void setTimePoint(double timePoint) {
		this.timePoint = timePoint;
	}
}
